package com.xy.biz.xd.controller;

import com.xy.biz.fd.domain.req.documentCode.GetDocumentByCodeRequest;
import com.xy.biz.xd.domain.query.DocumentFlowHandleQuery;
import com.xy.biz.xd.domain.req.GetDocumentFlowHandleRequest;
import com.xy.biz.xd.domain.req.GetDocumentFlowSimpleHandlesRequest;
import com.xy.biz.xd.domain.resp.DocumentFlowHandleTimeLineResponse;
import com.xy.biz.xd.domain.resp.GetDocumentFlowHandleResponse;
import com.xy.biz.xd.domain.tree.UserTreeItem;
import com.xy.biz.xd.service.DocumentFlowHandleService;
import com.xy.lang.domain.Result;
import com.xy.lang.domain.treeing.TreeItem;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author wwj
 * @Date 2021/3/11
 */
@Api(tags = "文档流程处理历史服务")
@Slf4j
@RequestMapping("/api/xd/document_flow_handle")
@RestController
public class DocumentFlowHandleController {

    @Autowired
    private DocumentFlowHandleService documentFlowHandleService;


    @ApiOperation("获取某流程某节点处理历史")
    @PostMapping(value = "/node_handle")
    public Result<List<GetDocumentFlowHandleResponse>> listDocumentFlowHandleByPhase(@RequestBody GetDocumentFlowHandleRequest request) {
        return documentFlowHandleService.listDocumentFlowHandleByPhase(DocumentFlowHandleQuery.max()
                .documentFlowId(request.getDocumentFlowId())
                .phase(request.getPhase()).build());
    }

    @ApiOperation("根据文件编号获取某流程某节点最新处理历史")
    @Validatable
    @PostMapping(value = "/node_handle_by_code")
    public Result<List<GetDocumentFlowHandleResponse>> listDocumentFlowHandleByPhase1(@RequestBody GetDocumentByCodeRequest request) {
        return documentFlowHandleService.listDocumentFlowHandleByDocumentCode(request);
    }

    @ApiOperation("获取各流程节点处理简单")
    @PostMapping(value = "/simple_nodes_handle")
    public Result<List<DocumentFlowHandleTimeLineResponse>> listSimpleNodesHandle(@RequestBody GetDocumentFlowSimpleHandlesRequest request) {
        return documentFlowHandleService.listDocumentFlowSimpleNodesHandle(request);
    }

    @ApiOperation("获取各流程节点处理")
    @PostMapping(value = "/nodes_handle")
    public Result<List<GetDocumentFlowHandleResponse>> listNodesHandle(@RequestBody GetDocumentFlowSimpleHandlesRequest request) {
        return Result.success(documentFlowHandleService.listDocumentFlowNodesHandle(request));
    }

    @ApiOperation("获取起草人部门")
    @PostMapping(value = "/get_drafter_user_group")
    public Result<UserTreeItem> getDrafterUserGroup(@RequestBody GetDocumentFlowSimpleHandlesRequest request) {
        return documentFlowHandleService.getDrafterUserGroup(request);
    }
}
